//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    name: '南工程校园助手',
    slogan: '～喵～',
    rightDeclare: 'Copyright © 2019-2020 lss. All Rights Reserved.',
    dataDeclare: '所有数据仅供参考，一切以教务网为准',
    logoUrl: '../images/logo.png',

    askCurCourseFlag: true,
  },
  onLoad: function(e) {
  },
  goCourse: function(e) {
    // wx.showToast({
    //   title: '暂未开放，敬请期待',
    //   icon: 'none',
    //   duration: 2000,
    // });
    // wx.navigateTo({
    //   url: '../course/course',
    // });
    // let that = this;


    let hasGetCourse = wx.getStorageSync('hasGetCourse');
    console.log(e);
    if (hasGetCourse !== null && hasGetCourse) {
      wx.navigateTo({
        url: '../course/course?local=1',
      });
    } else {
      this.goLoginWithFId(e);
    }
    // wx.getStorage({
    //   key: 'hasGetCourse',
    //   success: function(res) {
    //     // wx.navigateTo({
    //     // url: '../login/login',
    //     // })
    //     console.log(res.data);
    //   },
    //   fail: function() {
    //     let fId = that.getFunctionId(e);
    //     console.log(fId);
    //     wx.navigateTo({
    //       url: '../login/login?fid=' + fId,
    //     });
    //   }
    // })
  },
  goCalendar: function(e) {
    wx.navigateTo({
      url: '../calendar/calendar'
    });
  },

  goGrade: function(e) {
    // this.goLoginWithFId(e);
    wx.showActionSheet({
      // itemList: ['教务成绩', '体测成绩 [内网]', '教务学分', '创新学分 [内网]', '绩点', '关闭'],
      itemList: ['教务成绩', '教务学分', '绩点', '关闭'],
      
      itemColor: '#363636',
      success(res) {
        let idx = res.tapIndex;
        let fid;
        switch (idx) {
          // case 0:
          //   fid = 101;
          //   break;
          // case 1:
          //   fid = 104;
          //   break;
          // case 2:
          //   fid = 102;
          //   break;
          // case 3:
          //   fid = 105;
          //   break;
          // case 4:
          //   fid = 103;
          //   break;
          // case 5:
          //   return;

          case 0:
            fid = 101;
            break;
          case 1:
            fid = 102;
            break;
          case 2:
            fid = 103;
            break;
          case 3:
            return;
        }
        wx.navigateTo({
          url: '../login/login?fid=' + fid,
        });
      },
      fail(res) {
        console.log(res.errMsg)
      }
    });
  },

  goCredit: function(e) {
    this.goLoginWithFId(e);
  },

  getFunctionId: function(e) {
    return e.currentTarget.dataset.fid;
  },

  goLoginWithFId(e) {
    let fId = this.getFunctionId(e);
    wx.navigateTo({
      url: '../login/login?fid=' + fId +"&fid2=-1",
    });
  },

  goNotice(e) {
    wx.navigateTo({
      url: '../notice/notice',
    });
  },

  goLibrary(e) {
    wx.navigateTo({
      url: '../library/library',
    });
  },

  goAbout(e) {
    wx.showModal({
      title: "声明",
      content: "\r\n1、所有数据仅供参考，一切以教务网为准" +
        "\r\n2、用户信息仅储存在本地，请放心使用" +
        "\r\n3、有任何问题请联系 : 117271416@qq.com | wx: Xia03090709" +
        "\r\n4、感谢您的使用",
      cancelText: '清除数据',
      success(res) {
        if (res.confirm) {} else if (res.cancel) {
          wx.clearStorage();
        }
      }
    });
  },

  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },

})